<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <script src="./axios.js"></script>
    <script src="./socket.io.js"></script>
    <style>
        .container{
            width: 500px;
            height: 500px;
            border: 1px solid;
            margin: 0 auto;
            position: relative;
        }
        .myinput{
            position: absolute;
            bottom: 50px;
            width: 480px;
            height: 50px;
        }
        button{
            position: absolute;
            bottom: 10px;
            right: 10px;
        }
    </style>
</head>

<body>
    <div id="app">
        <!-- {{message}} -->
        <!-- <ul>
            <li v-for="(item,key) in users" :key="key">姓名是{{item.name}}年龄是{{item.age}}</li>
        </ul> -->
        <div class="container">
            <ul>
                <li v-for="(item,key) in arr" :key="key">{{item}}</li>
            </ul>
            <textarea class="myinput" v-model="message"></textarea>
            <button @click="addmessage">发送</button>
        </div>
    </div>
    <script>
        let socket = io.connect();


        new Vue({
            el: "#app",
            data: {
                arr:[],
                users:[],
                message:"",
                // myarr:[]
                
            },
            methods:{
                addmessage(){
                    // this.arr.push(this.message);
                    // 向socket服务器发送事件
                    // this.myarr.push(this.message);
                    socket.emit("addmessage",this.message); 
                }
            },
            created: async function () {
                socket.on("sendmessage",res=>{
                    // console.log(res);
                    this.arr = res;
                })
                // let { data } = await axios.get("/getdata");
                // // console.log(data);
                // this.users = data;
            }
        })



    </script>
</body>

</html>